'''
Created on 23/11/2010

@author: Nami
'''

import random
import gameobjects

EFFECT_INVERT_CONTROLS = 0
EFFECT_SCALE_TIME = 1
EFFECT_PUSH = 2
EFFECT_SCALE_SIZE = 3
EFFECT_ATTRACT = 4
EFFECT_ROTATE = 5
EFFECT_PARALIZED = 6
EFFECT_INVISIBLE = 7
EFFECT_SCALE_ENERGY = 8
EFFECT_INVULNERABLE = 9
EFFECT_VULNERABLE = 10
EFFECT_SCALE_DAMAGE = 11
EFFECT_TRAIL = 12
EFFECT_FOLLOW = 13

class Effect(object):
    parent = None
    duration = 0
    effect_class = -1
    time_elapsed = 0
    remove = False
    
    def update(self, elapsed):
        self.time_elapsed += elapsed
        if self.duration > 0 and self.time_elapsed > self.duration:
            self.remove = True
    
    def run(self, params):
        pass
    
    def render(self, surface):
        pass
    
    def __init__(self, effect_class, duration = -1):
        self.effect_class = effect_class
        self.duration = duration

class EffectLibrary(object):
    '''
    classdocs
    '''

    eff = {}

    parent = None
    data = None
    random_id = None

    def add_effect(self, effect):
        effect.parent = self.parent
        self.eff[effect.effect_class] = effect

    def remove_effect(self, effect_class):
        del self.eff[effect_class]

    def get_effect(self, effect_class):
        pass
    
    def run_effect(self, effect_class, params):
        if not effect_class in self.eff:
            return None
        else:
            return self.eff[effect_class].run(params)

    def update(self, elapsed):
        to_remove = []
        for effect in self.eff.itervalues():
            effect.update(float(elapsed))
            if effect.remove:
                to_remove.append(effect)
        for effect in to_remove:
            self.remove_effect(effect.effect_class)

    def render(self):
        for effect in self.eff.itervalues():
            effect.render()

    def __init__(self,parent):
        '''
        Constructor
        '''
        self.parent = parent
        self.random_id = random.random()*random.random()
        self.eff = {}